package cn.ronghuanet.base.service.impl;

import cn.ronghuanet.base.mapper.BaseMapper;
import cn.ronghuanet.base.query.BaseQuery;
import cn.ronghuanet.base.service.IBaseService;
import cn.ronghuanet.base.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        //维护path路径
        /*
            1.新增 用户会选择一个parent 或者为null
            2.如果父级部门有值 查询父级部门

         */
        baseMapper.save(t);

    }

    @Override
    @Transactional
    public void update(T t) {

        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.queryById(id);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }


    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //用来查询数据的条数
        Long total =  baseMapper.count(query);
        List<T> list= baseMapper.queryPage(query);
        return new PageList<T>( total,list);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        baseMapper.batchRemove(ids);
    }

}
